<template>
  <div class="plot-assistant">
    <div class="assistant-header">
      <h2>AI 情节助手</h2>
      <div class="assistant-actions">
        <el-button type="primary" @click="generatePlot">生成情节</el-button>
        <el-button @click="analyzePlot">分析情节</el-button>
      </div>
    </div>
    
    <div class="assistant-content">
      <div class="plot-input">
        <el-input
          v-model="plotInput"
          type="textarea"
          :rows="6"
          placeholder="请输入当前情节内容，AI将帮助您续写或优化..."
        />
        <div class="plot-options">
          <el-select v-model="plotStyle" placeholder="情节风格" class="style-select">
            <el-option label="严肃" value="serious" />
            <el-option label="幽默" value="humorous" />
            <el-option label="悬疑" value="suspense" />
            <el-option label="轻松" value="light" />
          </el-select>
          <el-select v-model="plotLength" placeholder="续写长度" class="length-select">
            <el-option label="短篇" value="short" />
            <el-option label="中篇" value="medium" />
            <el-option label="长篇" value="long" />
          </el-select>
        </div>
      </div>
      
      <div class="plot-output">
        <div class="output-header">
          <h3>AI 生成结果</h3>
          <el-button-group>
            <el-button size="small" @click="applyPlot">应用</el-button>
            <el-button size="small" @click="regeneratePlot">重新生成</el-button>
          </el-button-group>
        </div>
        <div class="output-content">
          <div v-if="plotOutput" class="generated-plot">
            {{ plotOutput }}
          </div>
          <div v-else class="output-placeholder">
            点击"生成情节"按钮开始创作
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const plotInput = ref('')
const plotStyle = ref('')
const plotLength = ref('')
const plotOutput = ref('')

const generatePlot = () => {
  if (!plotInput.value) {
    ElMessage.warning('请输入当前情节内容')
    return
  }
  // 模拟 AI 生成
  plotOutput.value = '基于您提供的内容，AI 生成了以下情节发展：\n\n' +
    '主角在经历了一系列挫折后，终于找到了解决问题的方法。' +
    '在这个过程中，他遇到了一个关键人物，这个人物给了他重要的启示...'
}

const analyzePlot = () => {
  if (!plotInput.value) {
    ElMessage.warning('请输入需要分析的情节内容')
    return
  }
  ElMessage.success('情节分析完成')
}

const applyPlot = () => {
  if (!plotOutput.value) {
    ElMessage.warning('请先生成情节')
    return
  }
  ElMessage.success('已应用生成的情节')
}

const regeneratePlot = () => {
  generatePlot()
}
</script>

<style scoped>
.plot-assistant {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.assistant-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: #fff;
  border-radius: 8px;
}

.assistant-content {
  flex: 1;
  display: flex;
  gap: 24px;
}

.plot-input {
  flex: 1;
  background: #fff;
  border-radius: 8px;
  padding: 24px;
}

.plot-options {
  display: flex;
  gap: 16px;
  margin-top: 16px;
}

.plot-output {
  flex: 1;
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.output-content {
  flex: 1;
  background: #f5f7fa;
  border-radius: 4px;
  padding: 16px;
  overflow-y: auto;
}

.generated-plot {
  white-space: pre-wrap;
  line-height: 1.6;
}

.output-placeholder {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #909399;
}
</style> 